﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Presentation.Web.Admin.Areas.Open.Controllers
{
    public class AdvertiseController : Infrastructure.Crosscutting.NetFramework.Controllers.OpenBaseController
    {
        Application.Admin.Advertise.IOpenAdvertiseService openAdvertiseService;

        public AdvertiseController(Application.Admin.Advertise.IOpenAdvertiseService openAdvertise)
        {
            if (openAdvertise == null)
            {
                throw new ArgumentNullException("openAdvertiseService is null");
            }
            openAdvertiseService = openAdvertise;
        }

        public JsonResult GetRandOneAdvertise()
        {
            var data = openAdvertiseService.GetRandOneAdvertise();
            if (data == null)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(data, JsonRequestBehavior.AllowGet);
            }
        }

        public JsonResult GetAdvertiseById(int id)
        {
            var data = openAdvertiseService.GetAdvertiseById(id);
            if (data == null)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(data, JsonRequestBehavior.AllowGet);
            }
        }

        public JsonResult GetAllAdvertise()
        {
            var data = openAdvertiseService.GetAllAdvertise();
            if (data == null || data.Count <= 0)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(data, JsonRequestBehavior.AllowGet);
            }
        }
    }
}
